{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"帐号与安全\",\"紧急联系人\",\"联系我们\",\"关于旋风卫士\"]\n",
    "acts = ['Account', \"Emergency\", \"ContactUs\", \"About\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "template = \"\"\"\n",
    "    <View\n",
    "        android:layout_width=\"match_parent\"\n",
    "        android:layout_height=\"@dimen/space1\"\n",
    "        android:layout_marginTop=\"@dimen/space20\"\n",
    "        android:background=\"@color/gray\"\n",
    "    />\n",
    "    <TextView\n",
    "        android:id=\"@+id/tv{}\"\n",
    "        android:layout_width=\"match_parent\"\n",
    "        android:layout_height=\"@dimen/space40\"\n",
    "        android:drawableRight=\"@drawable/ic_rightarrow\"\n",
    "        android:gravity=\"center_vertical\"\n",
    "        android:paddingLeft=\"@dimen/space15\"\n",
    "        android:paddingRight=\"@dimen/space15\"\n",
    "        android:text=\"{}\"\n",
    "    />\n",
    "    \n",
    "    <View\n",
    "        android:layout_width=\"match_parent\"\n",
    "        android:layout_height=\"@dimen/space1\"\n",
    "        android:background=\"@color/gray\"\n",
    "    />\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_xml_name(actvt):\n",
    "    return \"\".join([\"_\" + i.lower() if i.isupper() else i for i in actvt])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "    <View\n",
      "        android:layout_width=\"match_parent\"\n",
      "        android:layout_height=\"@dimen/space1\"\n",
      "        android:layout_marginTop=\"@dimen/space20\"\n",
      "        android:background=\"@color/gray\"\n",
      "    />\n",
      "    <TextView\n",
      "        android:id=\"@+id/tv_account\"\n",
      "        android:layout_width=\"match_parent\"\n",
      "        android:layout_height=\"@dimen/space40\"\n",
      "        android:drawableRight=\"@drawable/ic_rightarrow\"\n",
      "        android:gravity=\"center_vertical\"\n",
      "        android:paddingLeft=\"@dimen/space15\"\n",
      "        android:paddingRight=\"@dimen/space15\"\n",
      "        android:text=\"帐号与安全\"\n",
      "    />\n",
      "    \n",
      "    <View\n",
      "        android:layout_width=\"match_parent\"\n",
      "        android:layout_height=\"@dimen/space1\"\n",
      "        android:background=\"@color/gray\"\n",
      "    />\n",
      "\n",
      "    <View\n",
      "        android:layout_width=\"match_parent\"\n",
      "        android:layout_height=\"@dimen/space1\"\n",
      "        android:layout_marginTop=\"@dimen/space20\"\n",
      "        android:background=\"@color/gray\"\n",
      "    />\n",
      "    <TextView\n",
      "        android:id=\"@+id/tv_emergency\"\n",
      "        android:layout_width=\"match_parent\"\n",
      "        android:layout_height=\"@dimen/space40\"\n",
      "        android:drawableRight=\"@drawable/ic_rightarrow\"\n",
      "        android:gravity=\"center_vertical\"\n",
      "        android:paddingLeft=\"@dimen/space15\"\n",
      "        android:paddingRight=\"@dimen/space15\"\n",
      "        android:text=\"紧急联系人\"\n",
      "    />\n",
      "    \n",
      "    <View\n",
      "        android:layout_width=\"match_parent\"\n",
      "        android:layout_height=\"@dimen/space1\"\n",
      "        android:background=\"@color/gray\"\n",
      "    />\n",
      "\n",
      "    <View\n",
      "        android:layout_width=\"match_parent\"\n",
      "        android:layout_height=\"@dimen/space1\"\n",
      "        android:layout_marginTop=\"@dimen/space20\"\n",
      "        android:background=\"@color/gray\"\n",
      "    />\n",
      "    <TextView\n",
      "        android:id=\"@+id/tv_contact_us\"\n",
      "        android:layout_width=\"match_parent\"\n",
      "        android:layout_height=\"@dimen/space40\"\n",
      "        android:drawableRight=\"@drawable/ic_rightarrow\"\n",
      "        android:gravity=\"center_vertical\"\n",
      "        android:paddingLeft=\"@dimen/space15\"\n",
      "        android:paddingRight=\"@dimen/space15\"\n",
      "        android:text=\"联系我们\"\n",
      "    />\n",
      "    \n",
      "    <View\n",
      "        android:layout_width=\"match_parent\"\n",
      "        android:layout_height=\"@dimen/space1\"\n",
      "        android:background=\"@color/gray\"\n",
      "    />\n",
      "\n",
      "    <View\n",
      "        android:layout_width=\"match_parent\"\n",
      "        android:layout_height=\"@dimen/space1\"\n",
      "        android:layout_marginTop=\"@dimen/space20\"\n",
      "        android:background=\"@color/gray\"\n",
      "    />\n",
      "    <TextView\n",
      "        android:id=\"@+id/tv_about\"\n",
      "        android:layout_width=\"match_parent\"\n",
      "        android:layout_height=\"@dimen/space40\"\n",
      "        android:drawableRight=\"@drawable/ic_rightarrow\"\n",
      "        android:gravity=\"center_vertical\"\n",
      "        android:paddingLeft=\"@dimen/space15\"\n",
      "        android:paddingRight=\"@dimen/space15\"\n",
      "        android:text=\"关于旋风卫士\"\n",
      "    />\n",
      "    \n",
      "    <View\n",
      "        android:layout_width=\"match_parent\"\n",
      "        android:layout_height=\"@dimen/space1\"\n",
      "        android:background=\"@color/gray\"\n",
      "    />\n"
     ]
    }
   ],
   "source": [
    "for i, name in enumerate(names):\n",
    "    print(template.format(get_xml_name(acts[i]), name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "findViewById(R.id.tv_account).setOnClickListener(this);\n",
      "findViewById(R.id.tv_emergency).setOnClickListener(this);\n",
      "findViewById(R.id.tv_contact_us).setOnClickListener(this);\n",
      "findViewById(R.id.tv_about).setOnClickListener(this);\n"
     ]
    }
   ],
   "source": [
    "for i, name in enumerate(names):\n",
    "    print(\"findViewById(R.id.tv{}).setOnClickListener(this);\".format(get_xml_name(acts[i])))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "click_template = \"\"\"}} else if (id == R.id.tv{}) {{\n",
    "    startActivity({}Activity.class);\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "} else if (id == R.id.tv_account) {\n",
      "    startActivity(AccountActivity.class);\n",
      "} else if (id == R.id.tv_emergency) {\n",
      "    startActivity(EmergencyActivity.class);\n",
      "} else if (id == R.id.tv_contact_us) {\n",
      "    startActivity(ContactUsActivity.class);\n",
      "} else if (id == R.id.tv_about) {\n",
      "    startActivity(AboutActivity.class);\n"
     ]
    }
   ],
   "source": [
    "for i, name in enumerate(names):\n",
    "    print(click_template.format(get_xml_name(acts[i]), acts[i]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
